package cn.ruituo.web;

import cn.ruituo.entity.Page;
import cn.ruituo.entity.Student;
import cn.ruituo.service.StudentService;
import cn.ruituo.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "StudentsServlet2",value = "/StudentsServlet2")
public class StudentsServlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo= StrUtil.toInt(request.getParameter("pageNo"),1);
        String sname=request.getParameter("sname");
        String qq=request.getParameter("qq");
        String tel=request.getParameter("telephone");
        Page<Student> paging = StudentService.service.paging(pageNo, 20, sname, qq, tel, null, null);

        String sb= JSON.toJSONStringWithDateFormat(paging,"yyyy-MM-dd",SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullStringAsEmpty);
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.print(sb);
    }
}
